<?php

/**
 * Contains "ViewClient" mvc view class
 *
 * LICENSE: MIT
 *
 * @author Peter Pippinger
 * @category PP
 * @package PP_Mvc
 * @copyright Copyright (c) 2013 Peter Pippinger
 * @license http://opensource.org/licenses/MIT
 * @version 1.1.0
 * @since Class exists since release 1.0.0
 */

/**
 * "ViewClient" mvc view class
 *
 * Provides view handling for mvc template
 *
 * @author Peter Pippinger
 * @category PP
 * @package PP_Mvc
 * @copyright Copyright (c) 2013 Peter Pippinger
 * @license http://opensource.org/licenses/MIT
 * @version 1.1.0
 * @since Class exists since release 1.0.0
 */
class ViewClient extends View
{

	/**
	 * Model object.
	 *
	 * @var object
	 */
	protected $model;

	/**
	 * Controller object.
	 *
	 * @var object
	 */
	protected $controller;

	/**
	 * Initializes the view.
	 *
	 * @param ControllerClient $controller        	
	 * @param ModelClient $model        	
	 */
	public function __construct(ControllerClient $controller, ModelClient $model)
	{
		$this->controller = $controller;
		$this->model = $model;
	}

	/**
	 * Returns the output of the view.
	 *
	 * @return string
	 */
	public function output()
	{
		return parent::evalToString("?>" . file_get_contents(dirname(__FILE__) . "/phtml/Client.phtml"));
	}

	public function getPlaylistHtml()
	{
		$html = '';
		
		if ($result = Application::$mysqli->query('SELECT * FROM playlist WHERE server_id="' . Application::$mysqli->escape_string($_REQUEST['tp']) . '" AND client_id="' . Application::$mysqli->escape_string(Application::$_browserId) . '"')) {
			while ($row = $result->fetch_assoc()) {
				$html .= '<li class="ui-state-default"><input name="playlistIds[]" type="hidden" value="' . $row['video_id'] . '"><a href="https://www.youtube.com/watch?v=' . $row['video_id'] . '" target="_blank"><img class="dragAndDropImage" src="//i.ytimg.com/vi/' . $row['video_id'] . '/mqdefault.jpg"></a></li>';
			}
			$result->free();
		}
		return $html;
	}
}
